import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
export default defineConfig({
    plugins: [
        vue(),
        vueJsx(),

        AutoImport({
            include: [
                // 包含哪些文件。
                /\.[tj]sx?$/,
                /\.vue$/,
                /\.vue\?vue/
            ],
            // global imports to register
            imports: [
                // 插件预设支持导入的api
                "vue",
                "vue-router",
                "pinia",
                // 自定义导入的api
                {
                    axios: [
                        // default imports
                        ["default", "axios"] // import { default as axios } from 'axios',
                    ]
                }
            ],
            eslintrc: {
                enabled: false,
                filepath: "./.eslintrc-auto-import.json",
                globalsPropValue: true
            },
            dts: "./auto-imports.d.ts" // 生成在src路径下路径名为 auto-import.d.ts的声明文件
        })
    ],
    resolve: {
        alias: {
            "@": fileURLToPath(new URL("./src", import.meta.url)),
            styles: fileURLToPath(new URL("./src/assets/styles", import.meta.url))
        }
    },
    base: "./",
    build: {
        chunkSizeWarningLimit: 1500,
        emptyOutDir: true,
        sourcemap: false, // 源代码映射
        rollupOptions: {
            output: {
                // 拆分为块打包
                manualChunks(id) {
                    if (id.includes("node_modules")) {
                        return id.toString().split("node_modules/")[1].split("/")[0].toString();
                    }
                }
            }
        }
    },
    server: {
        port: 3000,
        host: "0.0.0.0",
        proxy: {
            "/api": {
                target: "http://192.168.1.112:5000",
                rewrite: (path) => path.replace(/^\/api/, "") // 路径重写
            },
            "/esart": {
                target: "http://192.168.1.63:5000"
            },
            "/keyword": {
                target: "http://192.168.1.63:5000"
            },
            "/link_system": {
                target: "http://192.168.1.101:5300",
                rewrite: (path) => path.replace(/^\/link_system/, "") // 路径重写
            }
        }
    }
});
